create table trailing_white_space ([Table Name] varchar(100),[Row Count] int, [Total Trailing WhiteSpace] int) insert trailing_white_space exec sp_msforeachtable ' if (columnproperty(object_id(''?''), ''data'', ''AllowsNull'') is not null) if exists (select 1 from ? where len(data) < datalength(data)) select ''?'', count(*), sum(datalength(data) - len(data)) from ? where len(data) < datalength(data)' select * from trailing_white_space select sum([Total Trailing WhiteSpace] from trailing_white_space